import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/login',
      name: 'login',
      meta: { title: '登录' },
      component: () => import('@/components/Login.vue')
    },
    {
      path: '/register',
      name: 'register',
      meta: { title: '注册' },
      component: () => import('@/components/Register.vue')
    },
    {
      path: '/forgetPwd',
      name: 'forgetPwd',
      meta: { title: '忘记密码' },
      component: () => import('@/components/ForgetPwd.vue')
    },
    {
      path: '/addLoginAuth',
      name: 'addLoginAuth',
      meta: { title: '用户登录授权', requireAuth: true },
      component: () => import('@/components/AddLoginAuth.vue')
    },
    {
      path: '/addAdminLoginAuth',
      name: 'addAdminLoginAuth',
      meta: { title: '管理员登录授权', requireAuth: true, requireRole: 'admin' },
      component: () => import('@/components/AddAdminLoginAuth.vue')
    },
    {
      path: '/404',
      name: '404',
      meta: { title: '404' },
      component: () => import('@/components/404.vue')
    },
    {
      path: '/',
      name: 'home',
      component: () => import('@/components/users/Index.vue'),
      redirect: '/home',
      children: [
        {
          path: '/home',
          name: 'UsersHome',
          meta: { title: '首页' },
          component: () => import('@/components/users/Home.vue')
        },
        {
          path: '/goodsInfo/:gId',
          name: 'goodsInfo',
          meta: { title: '商品详情' },
          component: () => import('@/components/users/goods/GoodsInfo.vue')
        },
        {
          path: '/addGoods',
          name: 'addGoods',
          meta: { title: '发布商品信息', requireAuth: true, requireRole: 'business' },
          component: () => import('@/components/users/goods/AddGoods.vue')
        },
        {
          path: '/addGoodImgs/:gId',
          name: 'addGoodImgs',
          meta: { title: '发布商品图片', requireAuth: true, requireRole: 'business' },
          component: () => import('@/components/users/goods/AddGoodImgs.vue')
        },
        {
          path: '/updateGoods/:gId',
          name: 'updateGoods',
          meta: { title: '修改商品信息', requireAuth: true, requireRole: 'business' },
          component: () => import('@/components/users/goods/UpdateGoods.vue')
        },
        {
          path: '/updateGoodImgs/:gId',
          name: 'updateGoodImgs',
          meta: { title: '修改商品图片', requireAuth: true, requireRole: 'business' },
          component: () => import('@/components/users/goods/UpdateGoodImgs.vue')
        },
        {
          path: '/goodsList',
          name: 'goodsList',
          meta: { title: '商城' },
          component: () => import('@/components/users/goods/GoodsList.vue')
        },
        {
          path: '/wantGoodsInfo/:wgId',
          name: 'wantGoodsInfo',
          meta: { title: '求购商品详情' },
          component: () => import('@/components/users/wantGoods/WantGoodsInfo.vue')
        },
        {
          path: '/addWantGoods',
          name: 'addWantGoods',
          meta: { title: '发布求购商品信息', requireAuth: true, requireRole: 'business' },
          component: () => import('@/components/users/wantGoods/AddWantGoods.vue')
        },
        {
          path: '/addWantGoodImgs/:wgId',
          name: 'addWantGoodImgs',
          meta: { title: '发布求购商品图片', requireAuth: true, requireRole: 'business' },
          component: () => import('@/components/users/wantGoods/AddWantGoodImgs.vue')
        },
        {
          path: '/updateWantGoods/:wgId',
          name: 'updateWantGoods',
          meta: { title: '修改求购商品信息', requireAuth: true, requireRole: 'business' },
          component: () => import('@/components/users/wantGoods/UpdateWantGoods.vue')
        },
        {
          path: '/updateWantGoodImgs/:wgId',
          name: 'updateWantGoodImgs',
          meta: { title: '修改求购商品图片', requireAuth: true, requireRole: 'business' },
          component: () => import('@/components/users/wantGoods/UpdateWantGoodImgs.vue')
        },
        {
          path: '/wantGoodsList',
          name: 'wantGoodsList',
          meta: { title: '求购商城' },
          component: () => import('@/components/users/wantGoods/WantGoodsList.vue')
        },
        {
          path: '/addUserAuth',
          name: 'addUserAuth',
          meta: { title: '实名认证', requireAuth: true },
          component: () => import('@/components/users/userAuth/AddUserAuth.vue')
        },
        {
          path: '/updateAlipay',
          name: 'updateAlipay',
          meta: { title: '修改支付宝号', requireAuth: true, requireRole: 'business' },
          component: () => import('@/components/users/userAuth/UpdateAlipay.vue')
        },
        {
          path: '/addPrivateMsg/:id/:gId',
          name: 'addPrivateMsg',
          meta: { title: '发送宝贝私信', requireAuth: true },
          component: () => import('@/components/users/privateMsg/AddPrivateMsg.vue')
        },
        {
          path: '/addWantPrivateMsg/:id/:wgId',
          name: 'addWantPrivateMsg',
          meta: { title: '发送求购私信', requireAuth: true },
          component: () => import('@/components/users/privateMsg/AddWantPrivateMsg.vue')
        },
        {
          path: '/userInfo/:uId',
          name: 'userInfo',
          meta: { title: '用户主页', requireAuth: true },
          component: () => import('@/components/users/userAuth/UserInfo.vue')
        },
        {
          path: '/shopCar',
          name: 'shopCar',
          meta: { title: '购物车', requireAuth: true },
          component: () => import('@/components/users/shopCar/ShopCar.vue')
        },
        {
          path: '/confirmOrder',
          name: 'confirmOrder',
          meta: { title: '确认订单', requireAuth: true, requireRole: 'business' },
          component: () => import('@/components/users/orders/ConfirmOrder.vue')
        },
        {
          path: '/imConfirmOrder/:gId',
          name: 'imConfirmOrder',
          meta: { title: '确认订单', requireAuth: true, requireRole: 'business' },
          component: () => import('@/components/users/orders/ImConfirmOrder.vue')
        },
        {
          path: '/returnUrl',
          name: 'returnUrl',
          meta: { title: '支付成功' },
          component: () => import('@/components/users/orders/ReturnUrl.vue')
        },
        {
          path: '/userIndex',
          name: 'userIndex',
          component: () => import('@/components/users/userHome/UserIndex.vue'),
          redirect: '/userHome',
          children: [
            {
              path: '/userHome',
              name: 'userHome',
              meta: { title: '个人主页', requireAuth: true },
              component: () => import('@/components/users/userHome/UserHome.vue')
            },
            {
              path: '/receiveAddress',
              name: 'receiveAddress',
              meta: { title: '收货地址', requireAuth: true },
              component: () => import('@/components/users/userHome/ReceiveAddress.vue')
            },
            {
              path: '/updatePwd',
              name: 'updatePwd',
              meta: { title: '修改密码', requireAuth: true },
              component: () => import('@/components/users/userHome/UpdatePwd.vue')
            },
            {
              path: '/myFollow',
              name: 'myFollow',
              meta: { title: '我的关注', requireAuth: true },
              component: () => import('@/components/users/userHome/MyFollow.vue')
            },
            {
              path: '/myCollection',
              name: 'myCollection',
              meta: { title: '我的收藏', requireAuth: true },
              component: () => import('@/components/users/userHome/MyCollection.vue')
            },
            {
              path: '/myGoods',
              name: 'myGoods',
              meta: { title: '商品管理', requireAuth: true, requireRole: 'business' },
              component: () => import('@/components/users/userHome/MyGoods.vue')
            },
            {
              path: '/myWants',
              name: 'myWants',
              meta: { title: '求购管理', requireAuth: true, requireRole: 'business' },
              component: () => import('@/components/users/userHome/MyWants.vue')
            },
            {
              path: '/mySellOrders',
              name: 'mySellOrders',
              meta: { title: '我卖出的', requireAuth: true, requireRole: 'business' },
              component: () => import('@/components/users/userHome/MySellOrders.vue')
            },
            {
              path: '/myBuyOrders',
              name: 'myBuyOrders',
              meta: { title: '我买到的', requireAuth: true, requireRole: 'business' },
              component: () => import('@/components/users/userHome/MyBuyOrders.vue')
            },
            {
              path: '/myInfo',
              name: 'myInfo',
              meta: { title: '我的消息', requireAuth: true },
              component: () => import('@/components/users/userHome/MyInfo.vue')
            }
          ]
        }
      ]
    },
    {
      path: '/admin',
      name: 'index',
      component: () => import('@/components/admin/Index.vue'),
      redirect: '/admin/home',
      children: [
        {
          path: '/admin/home',
          name: 'AdminHome',
          meta: { title: '管理员首页', requireAuth: true, requireRole: 'admin' },
          component: () => import('@/components/admin/Home.vue')
        },
        {
          path: '/admin/types',
          name: 'types',
          meta: { title: '类别管理', requireAuth: true, requireRole: 'admin' },
          component: () => import('@/components/admin/Types.vue')
        },
        {
          path: '/admin/users',
          name: 'users',
          meta: { title: '用户管理', requireAuth: true, requireRole: 'admin' },
          component: () => import('@/components/admin/Users.vue')
        },
        {
          path: '/admin/goods',
          name: 'goods',
          meta: { title: '商品管理', requireAuth: true, requireRole: 'admin' },
          component: () => import('@/components/admin/Goods.vue')
        },
        {
          path: '/admin/userinfo',
          name: 'userinfo',
          meta: { title: '个人主页', requireAuth: true, requireRole: 'admin' },
          component: () => import('@/components/admin/UserInfo.vue')
        },
        {
          path: '/admin/updatePwd',
          name: 'adminUpdatePwd',
          meta: { title: '修改密码', requireAuth: true, requireRole: 'admin' },
          component: () => import('@/components/admin/UpdatePwd.vue')
        },
        {
          path: '/admin/wantGoods',
          name: 'wantGoods',
          meta: { title: '求购管理', requireAuth: true, requireRole: 'admin' },
          component: () => import('@/components/admin/WantGoods.vue')
        },
        {
          path: '/admin/notice',
          name: 'notice',
          meta: { title: '通知管理', requireAuth: true, requireRole: 'admin' },
          component: () => import('@/components/admin/Notice.vue')
        },
        {
          path: '/admin/orders',
          name: 'orders',
          meta: { title: '订单管理', requireAuth: true, requireRole: 'admin' },
          component: () => import('@/components/admin/Orders.vue')
        },
        {
          path: '/admin/comments',
          name: 'comments',
          meta: { title: '商品评论', requireAuth: true, requireRole: 'admin' },
          component: () => import('@/components/admin/Comments.vue')
        },
        {
          path: '/admin/wantComments',
          name: 'wantComments',
          meta: { title: '求购评论', requireAuth: true, requireRole: 'admin' },
          component: () => import('@/components/admin/WantComments.vue')
        },
        {
          path: '/admin/transfer',
          name: 'transfer',
          meta: { title: '转账管理', requireAuth: true, requireRole: 'admin' },
          component: () => import('@/components/admin/Transfer.vue')
        }
      ]
    }
  ]
})
